"""
Case Type   : USTORE
Case Name   : 验证参数max_undo_workers的边界值
Create At   : 2025/3/10
Owner       : wan005
Description :
    1.查询参数默认值
    2.修改参数值为1，查询参数值
    3.修改参数值为100，查询参数值
Expect      :
    1.参数默认值为5
    2.修改成功
    3.修改成功
History     :
"""
import os
import unittest
import sys
from testcase.utils.Common import Common
from testcase.utils.CommonSH import CommonSH
from testcase.utils.Logger import Logger
from testcase.utils.Constant import Constant


class Security(unittest.TestCase):
    def setUp(self):
        self.logger = Logger()
        self.logger.info(f'---{os.path.basename(__file__)} start---')
        self.sh_primy = CommonSH('PrimaryDbUser')
        self.constant = Constant()
        self.common = Common()

    def test_ustore(self):
        text = '-----step1:查询参数默认值;expect:参数默认值5-----'
        self.logger.info(text)
        res1 = self.common.show_param('max_undo_workers')
        self.assertEqual('5', res1, text + '执行失败')

        text = '-----step2:修改参数值为1;expect:成功-----'
        self.logger.info(text)
        self.sh_primy.execute_gsguc('reload', self.constant.GSGUC_SUCCESS_MSG,
                                    'max_undo_workers=1')
        self.sh_primy.restart_db_cluster()
        res2 = self.common.show_param('max_undo_workers')
        self.assertEqual('1', res2, text + '执行失败')

        text = '-----step3:修改参数值为100;expect:成功-----'
        self.logger.info(text)
        self.sh_primy.execute_gsguc('reload', self.constant.GSGUC_SUCCESS_MSG,
                                    'max_undo_workers=100')
        self.sh_primy.restart_db_cluster()
        res3 = self.common.show_param('max_undo_workers')
        self.assertEqual('100', res3, text + '执行失败')

    def tearDown(self):
        text = '-----step1:清理环境，恢复配置;expect:成功-----'
        self.logger.info(text)
        self.sh_primy.execute_gsguc('reload', self.constant.GSGUC_SUCCESS_MSG,
                                    'max_undo_workers=5')
        self.sh_primy.restart_db_cluster()
        res = self.common.show_param('max_undo_workers')
        self.assertEqual('5', res, text + '执行失败')
        self.logger.info(f'---{os.path.basename(__file__)} end---')
